// pages/activities/activities.js
const {
    imgConfig
} = require('../../utils/config.js')
const {
    config
} = require('../../utils/config.js')
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        imgUrl: `${imgConfig}`,
        statusBarHeight: app.globalData.statusBarHeight,
        article: '',
        page: 1,
        limit: 7
    },
    back: function () {
        wx.navigateBack({});
    },
    //获取文章列表
    getContentList(categoryId){
        var that = this
        wx.request({
            url: `${config}/wechat/wxIndex/getContentList`,
            data: {
                deptId:app.globalData.deptId,//机构id
                categoryId:categoryId,
                page: that.data.page,//分页
                limit: that.data.limit
            },
            success(resp) {
                if (resp.data.code == 0) {
                    that.setData({
                        article: resp.data.webContentList.records
                    })
                }
            }

        })
    },
    //分页加载下一页
    pageLimit(){
        var that = this
        console.log("到底啦")
        if (that.data.article != "") {
            wx.showLoading({
                title: '玩命加载中',
                mask:true,
            })
            that.data.page++ //页码自增
            //发起请求
            wx.request({
                    url: `${config}/wechat/wxIndex/getContentList`,
                    data: {
                        deptId:app.globalData.deptId,
                        categoryId: that.data.categoryId,
                        page: that.data.page,
                        limit: that.data.limit
                    },
                success(resp) {
                    if (resp.data.code == 0) {
                        that.setData({
                            article: that.data.article.concat(resp.data.webContentList.records)
                        })
                    }
                    // 隐藏加载框
                    wx.hideLoading();
                }
            })
    }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
      console.log(options)
       this.getContentList(options.categoryId)
       this.setData({
        categoryId:options.categoryId
       })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {
     
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {
      
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
        this.pageLimit()
},

/**
 * 用户点击右上角分享
 */
onShareAppMessage() {

}
})